package ray.mgocc.title;

import ray.mgocc.Time;
import java.text.ParseException;

public class PlayTimeRequirement extends Requirement{
    private final Time threshold;
    private Time playtime = null;
    protected PlayTimeRequirement(Time threshold){
        this.threshold = threshold;
    }
    protected PlayTimeRequirement(long hours){
        try{
            this.threshold = new Time(hours+":00:00");
        }catch(ParseException e){
            throw new RuntimeException("bug.",e);
        }
    }
    public void setPlayTime(Time playtime){
        this.playtime = playtime;
    }
    public Time getPlayTime(){
        Time playtime;
        if(null==this.playtime){
            playtime = new Time();
        }else{
            playtime = this.playtime;
        }
        return playtime;
    }
    public double getRatio(){
        return ((double)getPlayTime().toSecond())/this.threshold.toSecond();
    }
    public String getName(){return "playtime";}
    public String toString(){
        return super.toString()+"("+threshold+"<="+getPlayTime()+")";
    }
}
